package com.bestv.search.common.service.impl;

import com.bestv.search.common.dao.SearchConfigDao;
import com.bestv.search.common.dataSource.DataSourceKey;
import com.bestv.search.common.model.SearchFieldInfo;
import com.bestv.search.common.service.SearchConfigManager;

import java.util.List;

public class SearchConfigManagerImpl implements SearchConfigManager {

    private SearchConfigDao searchConfigDao;

    public SearchConfigDao getSearchConfigDao() {
        return searchConfigDao;
    }

    public void setSearchConfigDao(SearchConfigDao searchConfigDao) {
        this.searchConfigDao = searchConfigDao;
    }

    @Override
    public SearchFieldInfo deleteSearchFieldInfo(DataSourceKey key, Long id) {
        return searchConfigDao.remove(id);
    }

    @Override
    public SearchFieldInfo getSearchFieldInfo(DataSourceKey key, Long id) {
        return searchConfigDao.get(id);
    }

    @Override
    public List<SearchFieldInfo> getSearchFieldInfos(DataSourceKey key) {
        return searchConfigDao.getAll();
    }

    @Override
    public SearchFieldInfo saveSearchFieldInfo(DataSourceKey key, SearchFieldInfo sfi) {
        return searchConfigDao.save(sfi);
    }

    @Override
    public int getSearchFieldInfosCount(DataSourceKey key) {
        return searchConfigDao.getSearchFieldInfosCount();
    }

    @Override
    public List<SearchFieldInfo> getSearchFieldInfos(DataSourceKey key, int start, int limit) {
        if (start == -1 || limit == -1)
            return searchConfigDao.getAll();
        return searchConfigDao.getSearchFieldInfoPaging(start, limit);
    }

    @Override
    public SearchFieldInfo getSearchInfoByName(DataSourceKey key, String name) {
        return searchConfigDao.getSearchInfoByName(name);
    }

    @Override
    public SearchFieldInfo getById(DataSourceKey key, Long id) {
        return searchConfigDao.get(id);
    }
}
